using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using QuanLyHocPhi.DAL;
using QuanLyHocPhi.Entity;
using QuanLyHocPhi.Util;
namespace QuanLyHocPhi
{
    public partial class frmThongkedadonghp : DevComponents.DotNetBar.Metro.MetroForm
    {
        HOA_DON_DAO daoHoaDon = new HOA_DON_DAO();
        HOA_DON_CT_DAO dapHoaDonCT = new HOA_DON_CT_DAO();
        DOI_TUONG_DAO daoDoiTuong = new DOI_TUONG_DAO();
        BIEN_LAI_DAO daoBienLai = new BIEN_LAI_DAO();
        IList<BIEN_LAI> dsBienLai;
        IList<string> dsLoaiDoiTuong;
        HOA_DON hoaDonHienTai = null;
        public frmThongkedadonghp()
        {
            InitializeComponent();
            dsLoaiDoiTuong = daoDoiTuong.GetAllObjectLOP();
            cbbDoiTuong.DataSource = dsLoaiDoiTuong;
            NapDuLieu();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void btnXem_Click(object sender, EventArgs e)
        {
            NapDuLieu();
        }

        private void frmThongkedadonghp_Load(object sender, EventArgs e)
        {

        }
        void NapDuLieu()
        {
            DateTime fromDate = dpkFrom.Value;
            DateTime toDate = dpkTo.Value;
            string loaiDoiTuong = cbbDoiTuong.Text;
            dsBienLai = daoHoaDon.QueryReceiptView(loaiDoiTuong, fromDate, toDate);
            objectBindingSource1.DataSource = dsBienLai;
            dgvBienLai.AutoGenerateColumns = false;
            dgvBienLai.AllowUserToAddRows = false;
            dgvBienLai.AllowUserToDeleteRows = false;
            dgvBienLai.DataSource = objectBindingSource1;
            //
            txtTongSoHoaDon.Text = dsBienLai.Count.ToString();
            float tongTien = 0;
            foreach (BIEN_LAI bl in dsBienLai) { tongTien += bl.SO_TIEN; }
            txtSoTienNhanDuoc.Text = tongTien.ToString();
        }
        void KiemTraNgay()
        {
            if (dpkFrom.Value < dpkTo.Value)
            {
                dpkTo.Value = dpkFrom.Value;
            }
        }

        private void dgvBienLai_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            
            if(dgvBienLai.CurrentRow.Index>-1){
                hoaDonHienTai = dsBienLai[dgvBienLai.CurrentRow.Index].MA_HOA_DON;
            
            IList<BIEN_LAI> ds = daoBienLai.GetReceiptsByInvoice(hoaDonHienTai.MA_HOA_DON);
            dgvBienLaiCT.AutoGenerateColumns = false;
            dgvBienLaiCT.AllowUserToAddRows = false;
            dgvBienLaiCT.AllowUserToDeleteRows = false;
            objectBindingSource2.DataSource = ds;
            dgvBienLaiCT.DataSource = objectBindingSource2;
            }
        }
    }
}